<?php
/**
 * Created by xuan.
 * Author: xuan
 * Date: 2018/8/3
 * Time: 18:24
 */

namespace app\api\model;
use think\Db;

class Goods extends BaseModel
{	
	protected $table = 'goods';
	
	public static function selectOneGoodsByID($id){
		$data = model("Goods")->where(array("id"=>$id))->find();
		return $data;
	}
	
	public static function GoodsLists(){
		$data = model("Goods")->select();
		return $data;
	}
	
	public static function addOneGoods($all)
    {
		$data = Goods::create([
			'multipic' => $all['multipic'],
			'goodsname' => $all['goodsname'],
			'orderby' => $all['orderby'],
			'catid' => $all['catid'],
			'isshow' => $all['catid'],
			'stock' => $all['stock'],
			'price' => $all['price'],
			'superreward' => $all['superreward'],
			'bigreward' => $all['bigreward'],
			'agentprice' => $all['agentprice'],
			'detail' => $all['detail'],
			'addtime' => date('Y-m-d H:i:s',time()),
			'updatetime' => date('Y-m-d H:i:s',time())
		]);
		  
		return $data;
    }
	
	public static function updOneGoods($all)
    {
		$data=Db::name('Goods')-> where('id',$all['id'])->update([
			'multipic' => $all['multipic'],
			'goodsname' => $all['goodsname'],
			'orderby' => $all['orderby'],
			'catid' => $all['catid'],
			'isshow' => $all['catid'],
			'stock' => $all['stock'],
			'price' => $all['price'],
			'superreward' => $all['superreward'],
			'bigreward' => $all['bigreward'],
			'agentprice' => $all['agentprice'],
			'detail' => $all['detail'],
			'updatetime' => date('Y-m-d H:i:s',time())
		]);
		return $data;
    }
	
	public static function delOneGoods($id)
    {
		$data=Db::name('Goods')-> where('id',$id)->delete();
		return $data;
    }
	
	/**
     * @param $where
     * @return array|false|\PDOStatement|string|\think\Model
     * 查询详情
     */
    public static function getListByWhere($where, $page = 0, $pageSize = 10,$cons = []){
        $pageSize = $pageSize <= 0 ? 10 : $pageSize;
        $list = Db::name('Goods')->where($where)->where($cons)->order('orderby','desc')->order('id DESC')->select();
		return $list;
    }
	
    public static function getCount($where = '',$cons = []){
        return Db::name('Goods')->where($where)->where($cons)->count();
    } 
	
}